/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Connection.DataAccess;
import Model.KhachHang;

/**
 *
 * @author My PC
 */
public class KhachHangController {
    public static boolean ThemKH(KhachHang kh)
    {
        try 
        {
            
           String sql = "insert into tblKhachHang(MA_KHACHHANG,"
                + " TEN_KHACHHANG,NGAYSINH,DIACHI,LOAI_KHACHHANG,GIOITINH,"
                + "SO_CMND,DIENTHOAI,EMAIL,NGAY_MUA) "
                   + "values (N'"+kh.getMaKhachhang()+"',N'"+kh.getTenKhachhang()+"',"
                   + " N'"+kh.getNgaysinh()+"',N'"+kh.getDiachi()+"',N'"+kh.getLoaikh()+"',"
                   + "N'"+kh.getGioitinh()+"',N'"+kh.getSocmnd()+"',N'"+kh.getDienthoai()+"',"
                   + "N'"+kh.getEmail()+"',N'"+kh.getNgaymua()+"')";
           DataAccess da=new DataAccess();
           da.executeUpdate(sql);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
     public static boolean XoaKH(KhachHang kh)
    {
        try 
        {
            
           String sql = "delete from tblKhachHang where MA_KHACHHANG =N'"+kh.getMaKhachhang()+"'";
           DataAccess da=new DataAccess();
           da.executeUpdate(sql);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
     public static boolean SuaKH(KhachHang kh)
    {
        try 
        {
            
           String sql = "UPDATE tblKhachHang SET TEN_KHACHHANG = "
                   + "N'"+ kh.getTenKhachhang()+"',NGAYSINH = '"+kh.getNgaysinh()+"',"
                   + "DiaChi = N'"+kh.getDiachi()+"',LOAI_KHACHHANG= N'"+kh.getLoaikh()+"' ,"
                   + "GIOITINH = N'"+kh.getGioitinh()+"',"
                   + "SO_CMND = N'"+kh.getSocmnd()+"',DIENTHOAI = N'"+kh.getDienthoai()+"',"
                   + "EMAIL = N'"+kh.getEmail()+"',"
                   + "NGAY_MUA= N'"+kh.getNgaymua()+"' WHERE MA_KHACHHANG = N'"+kh.getMaKhachhang()+"'";
           DataAccess da=new DataAccess();
           da.executeUpdate(sql);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
    
}
